local entids = {}

local function handleinfo(um)
	local ent = um:ReadShort()
	local nam = um:ReadString()
	local kind = um:ReadString()
	
	entids[ent] = {}
	entids[ent].name = nam
	entids[ent].buytype = kind
	
	--print(ent,nam,kind)
end
usermessage.Hook("buyerinfo", handleinfo)

local Start3D2D = cam.Start3D2D
local End3D2D = cam.End3D2D
local SetFont = surface.SetFont
local GetTextSize = surface.GetTextSize
local WordBox = draw.WordBox

local function drawinfo()
	for k,v in pairs(ents.FindByClass("npc_buyer")) do
		local info = entids[v:EntIndex()]
		
		if info == nil then return end
		
		local buytype = entids[v:EntIndex()].buytype
		local name = entids[v:EntIndex()].name	
		
		if buytype == nil then return end
		
		local nam = buyers[buytype]["nicename"]
		
		SetFont("HUDNumber5")
		local TextWidth = GetTextSize(name)
		local TextWidth2 = GetTextSize("Buying " .. nam)
		local TextWidth3 = GetTextSize("Current Price: $" .. v:GetDTInt(0))
		
		local ang = v:GetDTAngle(0)
		
		ang:RotateAroundAxis(ang:Up(), 90)
		ang:RotateAroundAxis(ang:Forward(), 90)
		
		if v:GetDTVector(0) != Vector(0,0,0) then
			Start3D2D(v:GetDTVector(0), ang,0.2)
				WordBox(2, -TextWidth*0.5 + 5, -30, name, "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
				WordBox(2, -TextWidth2*0.5 + 5, 18, "Buying " .. nam, "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
				WordBox(2, -TextWidth3*0.5 + 5, 66, "Current Price: $" .. v:GetDTInt(0), "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
			End3D2D()
		end
	end
end
hook.Add("PostDrawOpaqueRenderables","drawnpcsads",drawinfo)